package dtaskboard.client.toolbar;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

import dtaskboard.client.dto.RoleClass;
import dtaskboard.client.dto.RoleDTO;

public class ToolbarUtil {
  public static boolean checkAdminRole(Collection<RoleDTO> roles) {

    for (RoleDTO role : roles) {
      if (RoleClass.ADMIN.name().equals(role.getRole())) {
        return true;
      }
    }
    return false;
  }

  public static boolean checkManagerRole(Collection<RoleDTO> roles,
      String projectName) {
    for (RoleDTO role : roles) {
      if (RoleClass.MANAGER.name().equals(role.getRole())
          && projectName.equals(role.getProject())) {
        return true;
      }
    }
    return false;
  }

  public static Collection<String> ableProjects(Collection<RoleDTO> roles) {
    Collection<String> projects = new HashSet<String>();
    for (RoleDTO role : roles) {
      if (role.getProject() != null) {
        projects.add(role.getProject());
      }
    }
    List<String> sortedProjects = new ArrayList<String>(projects);
    Collections.sort(sortedProjects);
    return sortedProjects;
  }
}
